package org.microser.gataway.zuul.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.microser.gataway.zuul.system.entity.UserRole;
import org.microser.gataway.zuul.system.mapper.UserRoleMapper;
import org.microser.gataway.zuul.system.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liujiamiao
 * @since 2020-11-26
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    /**
     * 根据用户id得到角色id
     * @param id
     * @return
     */
    @Override
    public List<String> queryRoleIdsByUserId(String id) {
        QueryWrapper<UserRole> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",id);
        wrapper.select("role_id");
        List<UserRole> list = list(wrapper);
        List<String> collect = list.stream().map(entity -> {
            return entity.getRoleId();
        }).collect(Collectors.toList());
        return collect;
    }
}
